<?php
require_once("lib/util.php");
require_once("lib/db.php");
require_once("lib/incident.php");
$user_id = $_GET["user_id"];
session_start();
connect();
$user = get_user($user_id);
$user_incidents = query_user_incidents($user_id);
$user_incidents = set_total_rating($user_incidents);
render("user_profile", array("user" => $user, "user_incidents" => $user_incidents));
close();

function get_user($user_id){
$user_query= "SELECT * from users WHERE user_id = ?";
$user= query($user_query, array($user_id));
return $user[0];
}

function query_user_incidents($user_id){
	$query = "SELECT * FROM incidents WHERE creator_user_id = ?";
	$incidents = query($query, array($user_id));
	return $incidents;
}

